package yxy.cherry.battle.module.affix.buff;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.PropertyData;
import yxy.cherry.battle.module.PropertyType;
import yxy.cherry.battle.module.affix.AffixFactory;
import yxy.cherry.battle.module.affix.Buff;
import yxy.cherry.battle.module.affix.BuffType;
import yxy.cherry.battle.module.record.stream.RecordStream36ReduceHpAddAttribute;
import yxy.cherry.data.bean.skill;

/**
 * @author James
 * 属性加靠减血（苦肉）(消耗X%最大生命值，提高自身X%的X属性)
 * @date 2022/3/12 12:23
 */
@BuffType(Type = AffixFactory.BuffTypeEnum.属性加靠减血)
public class Affix78AddAttributePerByReduceHp extends Buff {


    public Affix78AddAttributePerByReduceHp(Fighter source, Fighter target, skill skilldata, int[] params) {
        super(source, target, skilldata, params);
    }
    private int getReducePer() {return getParam(0);}
    private int getAttribute() {return getParam(1);}
    private int getAddPer() {return getParam(2);}

    @Override
    public boolean exec(Fighter source, Fighter target) {
        if(this.getPropertyData()!=null){//如果执行过扣血就不扣血了
            return false;
        }

        long reduceHp = target.get生命() * getReducePer() / VALUE_比率分母;
        long addValue = target.getData().getPropertyData().getValue(PropertyType.forNumber(getAttribute())) * getAddPer() /VALUE_比率分母;
        target.set伤害(reduceHp);
        long finalValue = addValue;
        PropertyData propertyData = new PropertyData();
        propertyData.setValue(PropertyType.forNumber(getAttribute()), finalValue);
        setPropertyData(propertyData);

        if(!target.is活着()){
            getAffixAction().add死掉的武将(target);
            target.handle本方有死将();
        }

        getRecord().stream(new RecordStream36ReduceHpAddAttribute(target,target.get血量万分值(),getAttribute(),target.getProperty(PropertyType.forNumber(getAttribute())),this)).record();
        Battle.battleLogger(6,"属性加靠减血："+target.getName()+"生命："+target.get生命()+"减少比例："+getReducePer()+"增加属性："+getAttribute()+"增加值："+addValue);
        return true;
    }

    @Override
    public BuffType getBuffType() {
        return BuffType.属性加效果;
    }

    @Override
    public BuffStateType getBuffStateType() {
        return BuffStateType.属性加状态;
    }
}
